package org.example.course.controller;

import org.example.course.common.DataGridView;
import org.example.course.common.ResultObj;
import org.example.course.domain.Check;
import org.example.course.domain.Checkevaluation;
import org.example.course.domain.Course;
import org.example.course.service.CheckevaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname CheckevaluationController
 * @Description TODO
 * @Date 2020/5/9 15:22
 * @Created by
 */
@RestController
@RequestMapping("checkevaluations")
public class CheckevaluationController {
    @Autowired
    private CheckevaluationService service;


    /**
     * 更具课程ID查询 表3数据  返回合计 行
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "findBycourseId/{id}", method = RequestMethod.GET)
    public DataGridView findBycourseId(@PathVariable String id) {
        DataGridView dataGridView = service.findBycourseId(id);
        return dataGridView;
    }


    /**
     * 创建
     *
     * @param checkevaluation
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public ResultObj create(Checkevaluation checkevaluation) {
        if (checkevaluation == null) {
            return ResultObj.CREATE_ERROR;
        }
        if (service.create(checkevaluation)) {
            return ResultObj.CREATE_SUCCESS;
        }
        return ResultObj.CREATE_ERROR;
    }

    /**
     * 更新
     *
     * @param checkevaluation
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultObj update(Checkevaluation checkevaluation) {
        if (checkevaluation == null) {
            return ResultObj.UPDATE_ERROR;
        }
        if (service.update(checkevaluation)) {
            return ResultObj.UPDATE_SUCCESS;
        }
        return ResultObj.UPDATE_ERROR;
    }

}
